import 'package:common_utils/common_utils.dart';
import 'package:flutter/material.dart';
import 'package:flutter_chubao/binging/app_getx_user.dart';
import 'package:flutter_chubao/models/model_user.dart';
import 'package:flutter_chubao/tools/app_image_load.dart';
import 'package:flutter_chubao/tools/app_log.dart';
import 'package:flutter_chubao/tools/app_colors.dart';
import 'package:flutter_chubao/tools/app_textstyle.dart';
import 'package:flutter_chubao/widgets/app_widget_bg.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';

import 'app_mine_logic.dart';
import 'app_mine_state.dart';

/// @description:
/// @author
/// @date: 2023-12-13 10:17:00
class AppMinePage extends StatelessWidget {
  final AppMineLogic logic = Get.put(AppMineLogic());
  final AppMineState state = Get.find<AppMineLogic>().state;

  AppMinePage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetBuilder<AppMineLogic>(
      builder: (_) {
        UserEntity infoEntity = Get.find<AppGetxUser>().userEntity;
        DLog(infoEntity);
        return Scaffold(
          body: AppWidgetBg(
              // assets/icons/icon_bg_grey.png
              assetImage: 'icon_bg_mine',
              child: SafeArea(
                child: Column(
                  children: [
                    // _buildTopBtns(),
                    _buildUserHeader(),
                    SizedBox(
                      height: 19.w,
                    ),
                    _buildRows(),
                    SizedBox(
                      height: 10.w,
                    ),

                    // _buildBottomList(),
                    _buildBottomBtn()
                  ],
                ),
              )),
        );
      },
    );
  }

  Widget _buildTopBtns() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        // GestureDetector(
        //   child: SizedBox(
        //     width: 40.w,
        //     height: 44,
        //     child: Center(
        //       child: AppImage.getIconByPath('icon_mine_service',
        //           width: 24, color: Colors.white),
        //     ),
        //   ),
        // ),
        // GestureDetector(
        //   child: SizedBox(
        //     width: 40.w,
        //     height: 44,
        //     child: Center(
        //       child: AppImage.getIconByPath('icon_mine_messages',
        //           width: 24, color: Colors.white),
        //     ),
        //   ),
        // ),
        GestureDetector(
          behavior: HitTestBehavior.opaque,
          onTap: () {
            logic.clickRowsList('设置');
          },
          child: SizedBox(
            width: 40.w,
            height: 44,
            child: Center(
              child: AppImage.getIconByPath('icon_mine_setting',
                  width: 24, color: Colors.white),
            ),
          ),
        ),
        SizedBox(
          width: 6.w,
        )
      ],
    );
  }

  Widget _buildUserHeader() {
    return GestureDetector(
      onTap: () {
        // Get.toNamed(SSRouteNames.SSLoginPage);
      },
      behavior: HitTestBehavior.opaque,
      child: Container(
        padding: EdgeInsets.symmetric(horizontal: 14.w),
        child: Row(
          // mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            ClipRRect(
              borderRadius: BorderRadius.circular(25.w),
              child: AppImage.getLoad(
                  Get.find<AppGetxUser>().userEntity.headImage,
                  width: 50.w),
            ),
            // AppImage.getIconByPath('icon_placeholder', width: 50.w),
            SizedBox(
              width: 10.w,
            ),
            Expanded(
                child: Text(
              TextUtil.hideNumber(
                  Get.find<AppGetxUser>().userEntity.account ?? '*********'),
              style: AppTextStyle.getBoldTextStyle(
                  fontSize: 18, color: Colors.white),
            ))
          ],
        ),
      ),
    );
  }

  Widget _buildRows() {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: 14.w),
      padding: EdgeInsets.symmetric(vertical: 14.w),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(12)),
      child: Column(
        // mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: state.rows.map((e) {
          return InkWell(
              onTap: () {
                logic.clickRowsList(e['tit']);
              },
              child: Container(
                height: 40.w,
                padding: EdgeInsets.symmetric(horizontal: 12.w),
                child: Row(
                  children: [
                    // SizedBox(
                    //   width: 12.w,
                    // ),
                    AppImage.getIconByPath(e['im'], width: 20.w, height: 20.w),
                    SizedBox(
                      width: 4.w,
                    ),
                    Text(
                      e['tit'],
                      style: AppTextStyle.getNormalTextStyle(
                          fontSize: 13, color: kColorTextB70),
                    ),
                    const Expanded(child: SizedBox()),
                    Icon(
                      Icons.arrow_forward_ios_outlined,
                      size: 14.w,
                    ),
                  ],
                ),
              ));
        }).toList(),
      ),
    );
  }

  Widget _buildBottomBtn() {
    return GestureDetector(
      onTap: () {
        logic.clickRowsList('注销账号');
      },
      child: Container(
        height: 30.w,
        width: 100.w,
        alignment: Alignment.center,
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(15.w), color: Colors.black12),
        child: Text(
          '注销账号',
          style: AppTextStyle.getNormalTextStyle(fontSize: 12),
        ),
      ),
    );
  }

  Widget _buildBottomList() {
    return Container(
      alignment: Alignment.center,
      margin: EdgeInsets.symmetric(horizontal: 14.w),
      padding: EdgeInsets.symmetric(vertical: 19.w),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(12)),
      child: Wrap(
        // alignment: WrapAlignment.spaceAround,
        runSpacing: 19.w,
        children: state.rowsList
            .map(
              (map) => InkWell(
                onTap: () {
                  logic.clickRowsList(map['tit']);
                },
                child: SizedBox(
                  height: 46.w,
                  width: 86.w,
                  child: Column(
                    children: [
                      AppImage.getIconByPath(map['im'], width: 24.w),
                      SizedBox(
                        height: 5.w,
                      ),
                      Expanded(
                          child: Text(
                        map['tit'],
                        style: AppTextStyle.getNormalTextStyle(
                            fontSize: 14, color: kColorTextB70),
                      )),
                    ],
                  ),
                ),
              ),
              // Visibility(
              //     visible: state.rowsList.indexOf(map) !=
              //         state.rowsList.length - 1,
              //     child: SSWidgetSpace())
            )
            .toList(),
      ),
    );
  }
}
